<include file="Public/header" />
<include file="Public/menu" />

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            权限
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 权限管理</a></li>
            <li class="active">角色</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content"><div class="row"><div class="col-md-12"><div class="box">
        <div class="box-header">
            <h3 class="box-title"></h3>


            <!--<div class="form-inline pull-right">
                <form action="/manage/auth/roles" method="get" pjax-container="">
                    <fieldset>
                        <div class="input-group input-group-sm">
                            <span class="input-group-addon"><strong>Id</strong></span>
                            <input type="text" class="form-control" placeholder="Id" name="id" value="">
                        </div>

                        <div class="input-group input-group-sm">
                            <div class="input-group-btn">
                                <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                            </div>
                        </div>

                    </fieldset>
                </form>
            </div>-->


            <div class="btn-group pull-right" style="margin-right: 10px">
                <a href="{:U('manage/rbac/roleAdd')}" class="btn btn-sm btn-success"><i class="fa fa-save"></i>&nbsp;&nbsp;新增</a>
            </div>

        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <tbody>
                <tr>
                    <th><input type="checkbox" class="grid-select-all"></th>
                    <th>ID</th>
                    <th>角色名称</th>
                    <th>操作</th>
                </tr>
                <?php foreach($role as $v){ ?>
                <tr>
                    <td><input type="checkbox" class="grid-item" data-id="1"></td>
                    <td>{$v['id']}</td>
                    <td>{$v['name']}</td>
                    <td>
                        <a class="suggest" name="{$v['id']}" href="#"><i class="fa">添加权限</i></a>
                        <a href="{:U('rbac/roleEdit',array('id'=>$v['id']))}"><i class="fa fa-edit"></i></a>
                        <a onclick="if(confirm('确定删除?')==false)return false;" href="{:U('rbac/roleDel',array('id'=>$v['id']))}" data-id="31" class="_delete"><i class="fa fa-trash"></i></a>
                    </td>
                </tr>
                <?php } ?>
                </tbody>
            </table>
        </div>
        <div class="box-footer clearfix">
        <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;

        <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>

        {$page}
    </div>

        <!-- /.box-body -->
    </div></div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<script src="/Public/layer/layer.js"></script>
<script>
    ;!function(){
        $('.suggest').on('click', function(){
            var id = $(this).attr('name');
            layer.ready(function(){
                layer.open({
                    type: 2,
                    title: '添加权限',
                    fix: false,
                    maxmin: true,
                    shadeClose: true,
                    area: ['1100px', '800px'],
                    content: "/manage/rbac/roleAddMenu/id/"+id,
                    end: function(){
                        layer.tips('Hi', '#about', {tips: 1})
                    }
                });
            });
        });
    }();
</script>

<script data-exec-on-popstate>

    $(function () {

        $('.grid-select-all').change(function() {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.batch-delete').on('click', function() {
            var selected = [];
            $('.grid-item:checked').each(function(){
                selected.push($(this).data('id'));
            });

            if (selected.length == 0) {
                return;
            }

            if(confirm("Are you sure to delete this item ?")) {
                $.post('/manage/auth/roles/' + selected.join(), {_method:'delete','_token':'ALpaP7hXZ6s2dnAdE02Z6mUSHPt8RkYbcDRp6rpw'}, function(data){
                    $.pjax.reload('#pjax-container');
                    noty({
                        text: "<strong>Succeeded!</strong>",
                        type:'success',
                        timeout: 1000
                    });
                });
            }
        });
    });
</script>

